// https://www.acwing.com/problem/content/description/2/

#include <iostream>
#include <algorithm>

using namespace std;

const int T = 1010;
int N, maxVolume;
int volumes[T], prices[T];
int dp[T][T];

int main()
{
    cin >> N >> maxVolume;

    for (int i = 1; i <= N; i++)
        cin >> volumes[i] >> prices[i];

    // i 表示第i个物品, j 表示总体积不超过j
    for (int i = 1; i <= N; i++)
        for (int j = 0; j <= maxVolume; j++)
            // 第 i 个物品体积过大无法存入
            if (volumes[i] > j)
                dp[i][j] = dp[i - 1][j];
            else
            {
                // 装下的价值
                int v1 = dp[i - 1][j - volumes[i]] + prices[i];
                // 不装下的价值
                int v2 = dp[i - 1][j];

                dp[i][j] = max(v1, v2);
            }

    cout << dp[N][maxVolume] << endl;

    return 0;
}
